const db = uniCloud.database()
module.exports = {
	_before: function () { // 通用预处理器
	},
	// 获取文章列表
	getArtMul:async (event) =>{
		let { data:{skip = 0} } = event
		return await db.collection('articles').limit(7).skip(skip).orderBy('posttiem','desc').get()
	},
	// 获取单条数据
	getArtSingle:async (event) =>{
	let { data:{id} } = event
		return await db.collection('articles').doc(id).get()
	},
	// 添加文章
	addArtSingle:async (event) =>{
		let { data } = event
		return await db.collection('articles').add({
			...data,
			posttime:Date.now()
		})
	},
	// 删除文章
	delArtSingle:async (event) =>{
		let { data:{id} } = event
		return await db.collection('articles').doc(id).remove()
	},
	// 修改文章
	updateArtSingle:async (event) =>{
		let { data } = event
		return await db.collection('articles').doc(data._id).update({
			title:data.title,
			author:data.author,
			
		})
	},
}
